<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			#box1{
				width: 100px;
				height: 70px;				
				background-color: blueviolet;
			}
		</style>
		<script type="text/javascript">
			window.onload=function(){
				var box1=document.getElementById("box1");
				function bind(obj,eventStr,callback){
					if(obj.addEventListener){
						obj.addEventListener(eventStr,callback,false);
					}else{
						/*obj.attachEvent("on"+eventStr,callback);*//*直接写callback由IE浏览器调用会返回window元素，改成下面*/
						obj.attachEvent("on"+eventStr,function(){
							callback.call(obj);
						});
					}
				}
			/*滚轮事件*/
				box1.onmousewheel=function(event){/*火狐浏览器不支持onmousewheel*/
					event=event||window.event;
					if(event.wheelDelta>0||event.detail<0){/*一般浏览器支持wheelDelta>0向上，火狐支持detail<0向上*/
						box1.style.height=box1.clientHeight-20+"px";
					}else{
						box1.style.height=box1.clientHeight+20+"px";
					}
					event.preventDefault && event.preventDefault();/*火狐取消默认行为*//*有就自动调用*/
					return false;/*取消浏览器默认行为（滚动条 滚动行为）*/
				};
				bind(box1,"DOMMouseScroll",box1.onmousewheel );/*火狐支持DOMMouseScroll滚轮事件*/
				
			/*键盘事件1*/
				document.onkeydown=function(event){
					event=event || window.event;
					/*console.log("按键编码"+event.keyCode);*/
					if(event.keyCode===89 && event.ctrlKey){
						console.log("ctrl和y都被按下了");
					} 
				}
				/*document.onkeyup=function(){
					console.log("已松开");
				}*/
			/*键盘事件2*/
				var input=document.getElementsByTagName("input")[0];
				input.onkeydown=function(event){
					if(event.keyCode>=48 &&event.keyCode<=57){/*如果是数字，就取消默认行为（默认行为是显示在输入框中）*/
						return false;                           
					}
				}
				
			};
			
		</script>
	</head>
	<body style="height: 2000px;">
		<div id="box1"></div>
		<input type="text" />
	</body>
</html>
